package Thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * Completable  异步回调函数
 *
 *           1.没有返回值的异步方法
 *           2.有返回值的异步方法
 * @author hongtang.yang
 */
public class CompletableFeature_Study {
    public static void main(String[] args) throws ExecutionException, InterruptedException {


        //异步调用，没有返回值的方法
        CompletableFuture<Void> voidCompletableFuture = CompletableFuture.runAsync(() -> System.out.println(Thread.currentThread().getName() + "aaa"));

        voidCompletableFuture.get();


        CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "bbb");
            return 1/0;
        });
        Integer integer = integerCompletableFuture.whenComplete((t, u) -> {
            System.out.println("-----t=" + t);//方法返回值
            System.out.println("-----u=" + u);//异常返回值
        }).get();
        System.out.println(integer);
    }
}
